package com.zhbit.dao;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.transaction.annotation.Transactional;

import com.zhbit.domain.User;


public class UserDaoImpl implements UserDao{
	

	private String sql = "";
    //private Session session = null;
	@Resource
	private SessionFactory sessionFactory ;
	@Override
	public boolean Login(User user) {
		try{
			
			sql = "select username,password from User where username=?and password=?";
			 org.hibernate.Query query=getSession().createQuery(sql);
		        query.setParameter(0, user.getUsername());
		        query.setParameter(1, user.getPassword());
		        List list = query.list();
		        if(!list.isEmpty()){
		        	return true;
		        }else
		        	return false;
		}catch(Exception ex){
			ex.printStackTrace();
			return false;
		}
		
	}
	public Session getSession() {
//      session = Hibernate.getSessionFactory().openSession();
      //ts = session.beginTransaction();
      return this.sessionFactory.getCurrentSession();
  }
}
